package com.intretech.tj.live

import com.intretech.tj.global.tools.JSONTool
import com.intretech.tj.light.LightRequest
import com.intretech.tj.mqtt.MQTTVerticle
import com.intretech.tj.live.entity.DTO.DisableRequest
import jakarta.enterprise.context.ApplicationScoped


/**
 * 公共服务
 * @author Aecric
 * @date 2025/08/17
 */

@ApplicationScoped
class LivePublicVerticle(
    private val mqttVerticle: MQTTVerticle
) {

    fun stopVehicle(vehicleId: String){
        val disableRequest = DisableRequest(disabled = true)
        mqttVerticle.publish("device/vehicle/run${vehicleId}",0,JSONTool.toJSONString(disableRequest) )

    }


    fun refuseVehicle(vehicleId: String){
        val disableRequest = DisableRequest(disabled = false)
        mqttVerticle.publish("device/vehicle/run${vehicleId}",0,JSONTool.toJSONString(disableRequest) )


    }

    fun fireLightOpen(firelightId:Int){
        val disableRequest = DisableRequest(disabled = false)
        mqttVerticle.publish("device/firelight/${firelightId}",0,JSONTool.toJSONString(disableRequest) )

    }
    fun fireLightClose(firelightId:Int){
        val disableRequest = DisableRequest(disabled = true)
        mqttVerticle.publish("device/firelight/${firelightId}",0,JSONTool.toJSONString(disableRequest) )

    }


    fun modifyTrafficLight(lights: Array<LightRequest> ){
        mqttVerticle.publish("device/light/modify",0,JSONTool.toJSONString(lights) )

    }

    fun refuseTrafficLight(lightIds:Array<Int>){
        mqttVerticle.publish("device/light/recover",0,JSONTool.toJSONString(lightIds) )

    }

}